package com.glaze.edu.service.impl;

import com.glaze.edu.annotation.Autowired;
import com.glaze.edu.annotation.Service;
import com.glaze.edu.dao.AccountDao;
import com.glaze.edu.dao.impl.JdbcAccountDaoImpl;
import com.glaze.edu.pojo.Account;
import com.glaze.edu.service.TransferService;

/**
 * @author glaze
 */

@Service("transferService")
public class TransferServiceImpl implements TransferService {

//    private final AccountDao accountDao = new JdbcAccountDaoImpl();
    @Autowired
    private AccountDao accountDao;

    // private AccountDao accountDao = (AccountDao) BeanFactory.getBean("accountDao");


    @Override
    public void transfer(String fromCardNo, String toCardNo, int money) throws Exception {

            Account from = accountDao.queryAccountByCardNo(fromCardNo);
            Account to = accountDao.queryAccountByCardNo(toCardNo);

            from.setMoney(from.getMoney()-money);
            to.setMoney(to.getMoney()+money);

            accountDao.updateAccountByCardNo(to);

            accountDao.updateAccountByCardNo(from);


    }
}
